var jq=jQuery.noConflict();
/*
 * 获取下拉框中的所有水厂
 * */
function getSelectOfWaterPlant(action){	
	jq.ajax({    			
	    url:"../systemManage/GetSelectOfWaterPlant.action", //获得所有水厂的action
		type:'POST',
		data:{},
		dataType:'json',
		success:function(data){
			var jsonData = eval("(" + data + ")");
			if(null!=jsonData && jsonData.length>0){
				var obj = document.getElementById("waterplantId"); 
				for(var i=0;i<jsonData.length;++i){
					obj.options.add(new Option(jsonData[i].name,jsonData[i].id));
				}
				getDataList(action);
				//obj.options[0].selected=true;
			}
			
        }
   });
	//alert(action);
	
}

/*
 * 根据水厂ID获取该水厂已录入指标，然后显示相关列，隐藏未录入的列
 * */
function getDataList(action){
//jq("#requireDataBotton").click(function(){
	    //alert("init......");
	    var code=jq("#waterplantId").val();	
		var startTime=jq("#timeBegin").val();
		var endTime=jq("#timeEnd").val();
		var d = new Date();
		//var now = d.getFullYear()+"-"+(d.getMonth()+1)+"-0"+d.getDate();
		if(d.getMonth()+1<10)
		{
			now = d.getFullYear()+"-0"+(d.getMonth()+1)+"-"+d.getDate();
		}
		else
		{
			now = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}
		var distanceTime =(Date.parse(endTime)-Date.parse(startTime))/3600/1000;
		
		
		if(startTime==null || startTime.trim()=="")
		{
			alert("必须输入起始时间！！");
			return;
		}
		else if(endTime==null || endTime.trim()=="")
		{
			var date = new Date;
			endTime = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
		}
		else if(distanceTime<0)
		{
			alert("起始时间必须小于等于结束时间！！");
			return;
		}
		jq("#requireTable").bootstrapTable('refresh',{
		    url:action+'?code='+code+'&startTime='
		     +startTime+'&endTime='+endTime,
	     });
		getDataCols();
}

/*
 * 根据水厂ID获取该水厂已选指标，然后显示相关列，隐藏未选指标列
 * */
function getDataCols(){
	var code=jq("#waterplantId").val();
	//alert("code="+code);
	jq.ajax({			
	    url:"GetNormForNorm.action?code="+code, //
		type:'POST',
		data:{},
		dataType:'text',
		success:function(data){
			//alert(data);
			if("null"!=data && data.length>0){
				data=data.replace("\"","");
				data=data.replace("\"","");
				var norms = data.split("#");
				//alert(norms.length);
				jq('#requireTable').bootstrapTable('showColumn', "time");
				//jq('#requireTable').bootstrapTable('showColumn', "operation");
				//jq('#id').hide();
				jq('#requireTable').bootstrapTable('showColumn', "id");
				//jq('#operationButton').show();
				for(var i = 0; i < norms.length; i++) {
					//jq("."+norms[i]).show();					
					 //jq('#requireTable').bootstrapTable('showColumn', norms[i]);
				     jq('#requireTable').bootstrapTable('showColumn', norms[i]+"1");
					// jq('#requireTable').bootstrapTable('showColumn', norms[i]+"2");
					// jq('#requireTable').bootstrapTable('showColumn', norms[i]+"3");
				}
				
			}
        }
   });
}

/*
 * 在常规数据查询表格中添加操作按钮
 * */
/*function requireNormOperationButton(value) {
	value=jq.trim(value);
    return [
        '<a href="DelQualityNormol.action?id='+value+'"'+'>删除</a>'+ '<a href="GetQualityNormolById.action?id='+value+'"'+'>修改</a>'
    ].join('');
}*/

function requireNormOperationButton(value) {
	value=jq.trim(value);
	//alert(value);
    return [
        '<button onclick="deleteNormData('+value+')">删除</button>'+ '<button onclick="modifyNormData('+value+')">修改</button>'
    ].join('');
}
function deleteNormData(value){
	//alert(value);
	ui.confirm({
        tip:"你确定要删除这条记录吗？",
        dClass:'delete-user-dialog',
        yes:function(){        
    		window.location.href="DelQualityNormol?id="+value;
        }});
}

function modifyNormData(value){
	//alert(value);
	ui.confirm({
        tip:"你确定要修改这条记录吗？",
        dClass:'delete-user-dialog',
        yes:function(){         
    		window.location.href="GetQualityNormolById?id="+value;
        }});
}
/*
 * 在非常规数据查询表格中添加操作按钮
 * */
function requireNonNormOperationButton(value) {
	value=jq.trim(value);
	 return [
	         '<button onclick="deleteNonNormData('+value+')">删除</button>'+ '<button onclick="modifyNonNormData('+value+')">修改</button>'
	     ].join('');
}

function deleteNonNormData(value){
	//alert(value);
	ui.confirm({
        tip:"你确定要删除这条记录吗？",
        dClass:'delete-user-dialog',
        yes:function(){         
    		window.location.href="DelQualityNonNorm?id="+value;
        }});
}

function modifyNonNormData(value){
	//alert(value);
	ui.confirm({
        tip:"你确定要修改这条记录吗？",
        dClass:'delete-user-dialog',
        yes:function(){         
    		window.location.href="GetQualityNonNormById?id="+value;
        }});
}
/*
 * 在化学消毒剂数据查询表格中添加操作按钮
 * */
function requireAntissepticButton(value) {
	value=jq.trim(value);
	 return [
	         '<button onclick="deleteAntissepticData('+value+')">删除</button>'+ '<button onclick="modifyAntissepticData('+value+')">修改</button>'
	     ].join('');
}

function deleteAntissepticData(value){
	//alert(value);
	ui.confirm({
        tip:"你确定要删除这条记录吗？",
        dClass:'delete-user-dialog',
        yes:function(){         
    		window.location.href="DelAntisseptic?id="+value;
        }});
}

function modifyAntissepticData(value){
	//alert(value);
	ui.confirm({
        tip:"你确定要修改这条记录吗？",
        dClass:'delete-user-dialog',
        yes:function(){         
    		window.location.href="GetAntissepticById?id="+value;
        }});
}
/*window.operateEvents = {
		'click .delete': function (e, value, row, index) {
			alert("delete......");
		ui.confirm({
	        tip:"你确定要删除这条记录吗？",
	        dClass:'delete-user-dialog',
	        yes:function(){
	        	var code=row.id.toString();
	    		//alert(code);         
	    		window.location.href="DelQualityNormol?id="+code;
	        }});
		
		}

}

window.operateEvents = {
		'click .modify': function (e, value, row, index) {
			alert("modify......");
		ui.confirm({
	        tip:"你确定要修改这条记录吗？",
	        dClass:'modify-user-dialog',
	        yes:function(){
	        	var code=row.id.toString();
	    		//alert(code);         
	    		window.location.href="GetQualityNormolById?id="+code;
	        }});
		
		}
}*/
